<template>
  <div class="pagebox">
    <!--  -->
    <crumbs @goBack="goBack" :superiorMenu="['设备管理', '设备保养']" currentMenu="保养任务"></crumbs>
    <a-card :bordered="false" style="height: 100%; margin-top: 12px">
      <a-button @click="handleShowFilter" icon="filter"
        >筛选 <span class="filter-num" style="margin-left: 5px">{{ ' ' + filteredNums }}</span></a-button
      >
      <a-button @click="showColumn" icon="unordered-list" class="btns">设置列</a-button>
      <div class="right-btn">
        <a-button type="primary" @click="handleAdd"> +新建 </a-button>
      </div>
      <a-table
        row-key="id"
        :key="tableKey"
        size="middle"
        :scroll="{ x: scrollX, y: 'calc(100vh - 366px)' }"
        :hideDefaultSelections="false"
        :columns="columns"
        :dataSource="modelList"
        :pagination="false"
        @change="tableChange"
        class="j-table-force-nowrap"
        :components="drag(columns, 'INSPECTION_TASK_LIST')"
      >
        <span slot="actions" slot-scope="text, record">
          <a-button v-if="record.taskStatus == 0" type="link" @click="handleCheckReport(record)">保养汇报</a-button>
        </span>
        <!-- 行信息 -->
        <span
          slot="taskCode"
          :title="record.taskCode"
          slot-scope="text, record"
          class="btn-text"
          @click="handleDetail(record)"
        >
          {{ record.taskCode || '-' }}
        </span>
        <span slot="reporter" :title="record.reporterText" slot-scope="text, record">{{ record.reporterText || '-' }}</span>

        <span slot="amount" :title="commafyTofixed(record.amount, 2)" slot-scope="text, record">{{
          commafyTofixed(record.amount, 2)
        }}</span>
        <span slot="payAmount" :title="commafyTofixed(record.payAmount, 2)" slot-scope="text, record">{{
          commafyTofixed(record.payAmount, 2)
        }}</span>
        <span slot="unPayAmount" :title="commafyTofixed(record.unPayAmount, 2)" slot-scope="text, record">{{
          commafyTofixed(record.unPayAmount, 2)
        }}</span>
        <span slot="reportTime" :title="record.reportTime" slot-scope="text, record">{{ record.reportTime || '-' }}</span>
        <span
          slot="taskStatusText"
          :title="text"
          slot-scope="text, record"
          :style="{ color: taskStatusCheck(record.taskStatus) }"
          >{{ text }}</span
        >

        <!-- 输入框搜索 -->
        <div slot="searchInput" slot-scope="{ selectedKeys, confirm, clearFilters, column }" class="searchWorkOreder">
          <a-input
            placeholder="请输入"
            v-model="filterForm[column.dataIndex]"
            style="width: 188px; display: block"
            @pressEnter="handleSearch"
          />
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => handleSearch(selectedKeys, confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <a-icon
          slot="searchIcon"
          slot-scope="filtered"
          type="search"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
        <!-- 选择搜索 -->
        <div slot="selectDropdown" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
          <a-select
            mode="multiple"
            placeholder="请选择"
            allowClear
            style="width: 188px"
            v-model="filterForm[selectkeys(column.dataIndex)]"
            @change="(v) => changeSelect(v, selectkeys(column.dataIndex))"
          >
            <a-select-option
              v-for="(item, i) in selectOptions(column.dataIndex)"
              :key="i"
              :value="item[column.selectValue]"
              >{{ item[column.selectText] }}</a-select-option
            >
          </a-select>
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => handleSearch(confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <!-- 选择搜索 -->
        <div slot="selectDropdownSingle" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
          <a-select
            placeholder="请选择"
            allowClear
            style="width: 188px"
            v-model="filterForm[selectkeys(column.dataIndex)]"
            @change="(v) => changeSelect(v, selectkeys(column.dataIndex))"
          >
            <a-select-option
              v-for="(item, i) in selectOptions(column.dataIndex)"
              :key="i"
              :value="item[column.selectValue]"
              >{{ item[column.selectText] }}</a-select-option
            >
          </a-select>
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => handleSearch(confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <a-icon
          slot="selectIcon"
          slot-scope="filtered"
          type="filter"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
        <!-- 日期搜索 -->
        <div slot="datePicker" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
          <a-range-picker
            style="width: 188px"
            v-model="dateForm[column.dataIndex]"
            format="YYYY-MM-DD"
            :placeholder="['开始时间', '结束时间']"
            @change="(v) => onOk(v, column.dataIndex)"
          />
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => handleSearch(confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <a-icon
          slot="dateIcon"
          slot-scope="filtered"
          type="filter"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
        <!-- 人员选择 -->
        <div slot="selectPeople" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
          <j-select-user-by-dep
            @changeRow="userFilter"
            v-model="userIds"
            :limit="5"
            :seldep="true"
            :modalWidth="1000"
            :multi="true"
          ></j-select-user-by-dep>
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => handleSearch(confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <a-icon
          slot="peopleIcon"
          slot-scope="filtered"
          type="filter"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
      </a-table>
      <SetColumn
        columnName="设置列"
        ref="SetColumn"
        v-if="showSetColumn"
        @sureBtn="sureBtn"
        @cancelBtn="showSetColumn = false"
      />
    </a-card>
    <a-drawer placement="right" width="500" :visible="showFilter" @close="closeFilter">
      <div class="filter-body">
        <div slot="title" class="uni-card filter-tit">
          筛选 <span class="filter-num">{{ filteredNums }}</span>
        </div>
        <div class="uni-card" v-if="filteredNums > 0" style="background: #fff">
          <div v-for="(item, i) in filteredList" :key="i" v-show="item.text" class="tag-wrap">
            <span class="filter-tag" @click="delFiltered(item.key)">
              <span class="tag-text">{{ `${item.title}：${item.text}` }}</span>
              <a-icon type="close" style="float: right" />
            </span>
          </div>
        </div>
        <div style="overflow-y: scroll; flex: 1; padding: 0">
          <div class="uni-card" style="background: #fff">
            <a-form-model ref="ruleForm" layout="vertical" :model="filterForm">
              <a-form-model-item label="任务编号">
                <a-input v-model="filterForm.taskCode" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="方案名称">
                <a-input v-model="filterForm.programName" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="设备编号">
                <a-input v-model="filterForm.deviceCode" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="设备名称">
                <a-input v-model="filterForm.deviceName" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="汇报人">
                <j-select-user-by-dep
                  @changeRow="userFilter"
                  v-model="userIds"
                  :limit="5"
                  :seldep="true"
                  :modalWidth="1000"
                  :multi="true"
                ></j-select-user-by-dep>
              </a-form-model-item>
              <a-form-model-item label="状态">
                <a-select
                :getPopupContainer="(triggerNode) => triggerNode.parentNode"
                  placeholder="请选择"
                  allowClear
                  style="width: 100%"
                  v-model="filterForm['taskStatus']"
                  @change="(v) => changeSelect(v, 'taskStatus')"
                >
                  <a-select-option v-for="option in dictOptionsTaskStatus" :key="option.value" :value="option.value">{{
                    option.title
                  }}</a-select-option>
                </a-select>
              </a-form-model-item>
              <a-form-model-item label="设备类型">
                <a-select
                :getPopupContainer="(triggerNode) => triggerNode.parentNode"
                  mode="multiple"
                  placeholder="请选择"
                  allowClear
                  style="width: 100%"
                  v-model="filterForm['deviceCategory']"
                  @change="(v) => changeSelect(v, 'deviceCategory')"
                >
                  <a-select-option
                    v-for="option in dictOptionsDeviceCategory"
                    :key="option.value"
                    :value="option.value"
                    >{{ option.title }}</a-select-option
                  >
                </a-select>
              </a-form-model-item>
            </a-form-model>
            <a-form-model-item label="汇报时间">
              <a-range-picker
              :getCalendarContainer="getCalendarContainer()"
                style="width: 100%"
                v-model="dateForm['reportTime']"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="(v) => onOk(v, 'reportTime')"
              />
            </a-form-model-item>
            <a-form-model-item label="创建时间">
              <a-range-picker
              :getCalendarContainer="getCalendarContainer()"
                style="width: 100%"
                v-model="dateFormCreate['createTime']"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="(v) => onOkCreate(v, 'createTime')"
              />
            </a-form-model-item>
          </div>
        </div>
        <div class="footer-submit">
          <a-button class="margin-btn" @click="resetFilter">重置</a-button>
          <a-button type="primary" @click="handleFilter">确定</a-button>
        </div>
      </div>
    </a-drawer>
    <!-- 全选/分页 -->
    <div
      class="uni-card"
      :style="{
        margin: '20px -12px 0 -12px',
        background: '#fff',
        paddingLeft: '50px',
      }"
    >
      <div style="display: inline-block">
        <span>
          {{ `共 ${total} 条` }}
        </span>
      </div>
      <div style="display: inline-block; float: right">
        <a-pagination
          :total="total"
          v-model="current"
          :page-size-options="pageSizeOptions"
          :page-size="pageSize"
          @change="onChangePage"
          @showSizeChange="onShowSizeChange"
          show-quick-jumper
          show-size-changer
        />
      </div>
    </div>
    <windowForm ref="windowForm" @refresh="handleSearch"></windowForm>
    <maintenanceTasksReport ref="maintenanceTasksReport" @refresh="handleSearch"></maintenanceTasksReport>
    <windowDetail ref="windowDetail"></windowDetail>
  </div>
</template>
<script>
import SetColumn from '@/pubComponent/SetColumn.vue'
import crumbs from '@/components/crumbs.vue'
import { getNewColumns, subStrText, camelCase2UnderLine, commafyTofixed } from '@/utils/util'
import { API } from '@/api/requestFzs'
import { APILX } from '@/api/requestLx'
import moment from 'dayjs'
import { mapState } from 'vuex'
import { ajaxGetDictItems, getEnableOne } from '@/api/api'
import { maintenanceTaskList} from '@/api/erpApi'
import tableDragResize from '@/mixins/tableDragResize'
import { getDictModel } from '@/api/goodsManagement'
// 表头
const columnsValue = [
  {
    title: '任务编号',
    width: 180,
    fixed: 'left',
    ellipsis: true,
    dataIndex: 'taskCode',
    scopedSlots: {
      filterDropdown: 'searchInput',
      filterIcon: 'searchIcon',
      customRender: 'taskCode',
    },
  },
  {
    title: '方案名称',
    width: 150,
    ellipsis: true,
    dataIndex: 'programName',
    scopedSlots: {
      filterDropdown: 'searchInput',
      filterIcon: 'searchIcon',
      customRender: 'programName',
    },
  },
  {
    title: '设备编号',
    width: 150,
    ellipsis: true,
    dataIndex: 'deviceCode',
    scopedSlots: {
      filterDropdown: 'searchInput',
      filterIcon: 'searchIcon',
      customRender: 'deviceCode',
    },
  },
  {
    title: '设备名称',
    width: 150,
    ellipsis: true,
    dataIndex: 'deviceName',
    scopedSlots: {
      filterDropdown: 'searchInput',
      filterIcon: 'searchIcon',
      customRender: 'deviceName',
    },
  },
  {
    title: '汇报人',
    width: 100,
    ellipsis: true,
    dataIndex: 'reporter',
    scopedSlots: {
      filterDropdown: 'selectPeople',
      filterIcon: 'peopleIcon',
      customRender: 'reporter',
    },
  },
  {
    title: '状态',
    width: 100,
    ellipsis: true,
    dataIndex: 'taskStatusText',
    selectValue: 'value',
    selectText: 'text',
    scopedSlots: {
      filterDropdown: 'selectDropdownSingle',
      filterIcon: 'selectIcon',
      customRender: 'taskStatusText',
    },
  },
  {
    title: '设备类别',
    width: 100,
    ellipsis: true,
    dataIndex: 'deviceCategoryText',
    selectValue: 'value',
    selectText: 'text',
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'selectIcon',
      customRender: 'deviceCategoryText',
    },
  },
  {
    title: '汇报时间',
    width: 150,
    dataIndex: 'reportTime',
    scopedSlots: {
      customRender: 'reportTime',
    },
  },
  {
    title: '创建时间',
    width: 150,
    dataIndex: 'createTime',
    scopedSlots: {
      customRender: 'createTime',
    },
  },
]
const actionArr = [
  {
    fixed: 'right',
    title: '操作',
    width: 120,
    dataIndex: 'actions',
    ellipsis: true,
    scopedSlots: { customRender: 'actions' },
  },
]
export default {
  mixins: [tableDragResize],
  data() {
    return {
      dictOptionsTaskStatus: [], //任务状态字典值下拉数据
      dictOptionsDeviceCategory: [], //设备类别字典值下拉数据
      commafyTofixed,
      moment,
      subStrText,
      showFilter: false, // 筛选抽屉
      modelList: [], // 列表数据
      showSetColumn: false, // 显示
      //全选按钮
      indeterminate: false,
      checkAll: false,
      current: 1,
      total: 0,
      pageSize: 10,
      pageSizeOptions: ['10', '20', '30', '40', '50'],
      columnsValue,
      columns: [
        {
          title: '任务编号',
          width: 180,
          ellipsis: true,
          dataIndex: 'taskCode',
          scopedSlots: {
            filterDropdown: 'searchInput',
            filterIcon: 'searchIcon',
            customRender: 'taskCode',
          },
        },
        {
          title: '方案名称',
          width: 150,
          ellipsis: true,
          dataIndex: 'programName',
          scopedSlots: {
            filterDropdown: 'searchInput',
            filterIcon: 'searchIcon',
            customRender: 'programName',
          },
        },
        {
          title: '设备编号',
          width: 150,
          ellipsis: true,
          dataIndex: 'deviceCode',
          scopedSlots: {
            filterDropdown: 'searchInput',
            filterIcon: 'searchIcon',
            customRender: 'deviceCode',
          },
        },
        {
          title: '设备名称',
          width: 150,
          ellipsis: true,
          dataIndex: 'deviceName',
          scopedSlots: {
            filterDropdown: 'searchInput',
            filterIcon: 'searchIcon',
            customRender: 'deviceName',
          },
        },
        {
          title: '状态',
          width: 100,
          ellipsis: true,
          dataIndex: 'taskStatusText',
          selectValue: 'value',
          selectText: 'text',
          scopedSlots: {
            filterDropdown: 'selectDropdownSingle',
            filterIcon: 'selectIcon',
            customRender: 'taskStatusText',
          },
        },
        {
          title: '设备类别',
          width: 100,
          ellipsis: true,
          dataIndex: 'deviceCategoryText',
          selectValue: 'value',
          selectText: 'text',
          scopedSlots: {
            filterDropdown: 'selectDropdown',
            filterIcon: 'selectIcon',
            customRender: 'deviceCategoryText',
          },
        },
        // {
        //   fixed: 'right',
        //   title: '操作',
        //   width: 120,
        //   dataIndex: 'actions',
        //   ellipsis: true,
        //   scopedSlots: { customRender: 'actions' },
        // },
      ],
      filterForm: {
        taskCode: '',
        programName: '',
        deviceCode: '',
        deviceName: '',
        reportTime: null,
        reportDateStart: null,
        reportDateEnd: null,
        createTime: null,
        createDateStart: null,
        createDateEnd: null,
        reporter: '', //汇报人
        deviceCategory: undefined, //设备类型
        taskStatus: '', //任务状态
        // repairStatusList: ['not_effective', 'wait_receipt', 'repairing', 'wait_verify'],
      },
      filteredFormLable: {
        taskCode: '任务编号',
        programName: '方案名称',
        deviceCode: '设备编号',
        deviceName: '设备名称',
        reporter: '汇报人',
        reportTime: '汇报时间',
        createTime: '创建时间',
        deviceCategory: '设备类型',
        taskStatus: '任务状态',
      },
      sortForm: {
        sortType: '',
        sortColumn: '',
      },
      userIds: '' /* 选人组件绑定值 */,
      userNames: '' /* 筛选抽屉展示已选用户姓名 */,
      dateForm: {} /* 筛选日期绑定对象 */,
      dateFormCreate: {} /* 筛选日期绑定对象 */,
      customSelectList: [],
      applyStatusList: [],
      dealStatusList: [],
      loginUser: '',
      tableKey: 1.9
    }
  },
  components: {
    SetColumn,
    crumbs,
    windowForm: (resolve) => require(['@/views/baseManagement/devicesCare/maintenanceTasks/maintenanceTasksAdd'], resolve),
    maintenanceTasksReport: (resolve) => require(['@/views/baseManagement/devicesCare/maintenanceTasks/maintenanceTasksReport'], resolve),
    windowDetail: (resolve) => require(['@/views/baseManagement/devicesCare/maintenanceTasks/maintenanceTasksDetail'], resolve),
  },
  computed: {
    scrollX() {
      let xnum = 0
      for (let item of this.columns) {
        xnum += Number(item.width) || 0
      }
      return xnum
    },
    ...mapState({
      collapsed: (state) => state.user.collapsed,
    }),
    filteredList() {
      let list = []
      for (let key in this.filterForm) {
        if (key == 'reportTime') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.filterForm.reportDateStart
              ? moment(this.filterForm.reportDateStart).format('YYYY-MM-DD') +
                '-' +
                moment(this.filterForm.reportDateEnd).format('YYYY-MM-DD')
              : '',
            key,
          })
        } else if (key == 'createTime') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.filterForm.createDateStart
              ? moment(this.filterForm.createDateStart).format('YYYY-MM-DD') +
                '-' +
                moment(this.filterForm.createDateEnd).format('YYYY-MM-DD')
              : '',
            key,
          })
        } else if (key == 'reporter') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.userNames,
            key,
          })
        } else if (key == 'reportDateStart' || key == 'reportDateEnd') {
          // 什么都不干
        } else if (key == 'createDateStart' || key == 'createDateEnd') {
          // 什么都不干
        } else if (key == 'deviceCategory' || (key == 'taskStatus' && this.filterForm[key])) {
          console.log(this.filteredFormLable[key],this.statusToTxt(key, this.filterForm[key]),key,'---taskStatus');
          list.push({
            title: this.filteredFormLable[key],
            text: this.statusToTxt(key, this.filterForm[key]),
            key,
          })
        } else {
          list.push({
            title: this.filteredFormLable[key],
            text: this.filterForm[key],
            key,
          })
        }
      }
      return list
    },
    filteredNums() {
      let nums = 0
      for (let key in this.filterForm) {
        if (this.filterForm[key]) {
          nums += 1
          if (key == 'reportDateStart') {
            nums -= 1
          }
          if (key == 'createDateStart') {
            nums -= 1
          }
        }
      }
      return nums
    },
  },
  created() {
    let user = localStorage.getItem('pro__Login_Userinfo')
    this.loginUser = JSON.parse(user).value.id
    // this.filterForm.taskStatus.push('0')
    // this.filterForm.taskStatus = JSON.parse(JSON.stringify(this.filterForm.taskStatus))
  //  console.log(this.filterForm.taskStatus,'---this.filterForm.taskStatu');
   let arr = ['0']
   this.filterForm.taskStatus = '0'
  //  console.log(arr,'---arr');
   
    this.initData()
    this.requestData()

  },
  methods: {
    getCalendarContainer(){
      return triggerNode => triggerNode.parentNode;

    },
    changeSelect(v, key) {
      console.log(v,key,'---changeSelect')
      if (v.length == 0) {
        this.filterForm[key] = undefined
      }
    },
    selectkeys(key) {
      if (key == 'deviceCategoryText') {
        return 'deviceCategory'
      } else if (key == 'taskStatusText') {
        return 'taskStatus'
      }
    },
    selectOptions(key) {
      if (key == 'deviceCategoryText') {
        return this.dictOptionsDeviceCategory
      } else if (key == 'flowStatusText') {
        return this.applyStatusList
      } else if (key == 'taskStatusText') {
        return this.dictOptionsTaskStatus
      }
    },
    /* 筛选状态回显文字 */
    statusToTxt(key, val) {
      var valList = []
      if (key == 'taskStatus' && this.filterForm[key]) {
        for (let i = 0; i < val.length; i++) {
          const item = val[i]
          for (let j = 0; j < this.dictOptionsTaskStatus.length; j++) {
            const txt = this.dictOptionsTaskStatus[j]
            if (item == txt.value) {
              valList.push(txt.title)
            }
          }
        }
        return valList.join(',')
      } else if (key == 'deviceCategory' && this.filterForm[key]) {
        for (let i = 0; i < val.length; i++) {
          const item = val[i]
          for (let j = 0; j < this.dictOptionsDeviceCategory.length; j++) {
            const txt = this.dictOptionsDeviceCategory[j]
            if (item == txt.value) {
              valList.push(txt.title)
            }
          }
        }
        return valList.join(',')
      }
    },
    /* 状态颜色 */
    taskStatusCheck(v) {
      let checked = false
      if (v == '1') {
        checked = false
      } else if (v == '0') {
        checked = true
      }
      return checked ? '#ff943e' : '#00b042'
    },
    // 选人
    userFilter(v, row) {
      console.log(this.userIds)
      let uIds = []
      let uNames = []
      if (row.length > 0) {
        row.forEach((u) => {
          uIds.push(u.id)
          uNames.push(u.realname)
        })
        this.filterForm.reporter = uIds.join(',')
        this.userNames = uNames.join(',')
        this.handleSearch()
      } else {
        this.filterForm.reporter = ''
        this.userNames = ''
      }
    },
    /* 汇报时间选择 */
    onOk(value, key) {
      if (value.length == 0) {
        this.filterForm[`reportDateStart`] = ''
        this.filterForm[`reportDateEnd`] = ''
        this.filterForm[key] = ''
        return
      }
      this.filterForm[`reportDateStart`] = moment(value[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
      this.filterForm[`reportDateEnd`] = moment(value[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
    },
    /* 创建时间选择 */
    onOkCreate(value, key) {
      if (value.length == 0) {
        this.filterForm[`createDateStart`] = ''
        this.filterForm[`createDateEnd`] = ''
        this.filterForm[key] = ''
        return
      }
      this.filterForm[`createDateStart`] = moment(value[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
      this.filterForm[`createDateEnd`] = moment(value[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
    },
    // 排序
    tableChange(pagination, filters, sorter, { currentDataSource }) {
      console.log('看看这是啥33：', sorter)
      if (sorter.order) {
        let sortType = ''
        if (sorter.order == 'ascend') {
          sortType = 'ASC'
        } else {
          sortType = 'DESC'
        }
        this.sortForm = {
          sortType: sortType,
          sortColumn: camelCase2UnderLine(sorter.columnKey),
        }
        this.requestData()
      } else {
        this.sortForm = {
          sortType: '',
          sortColumn: '',
        }
        this.requestData()
      }
    },
    // 分页
    onChangePage(current, pageSize) {
      this.current = current
      this.pageSize = pageSize
      this.requestData(true)
    },
    onShowSizeChange(current, pageSize) {
      this.current = current
      this.pageSize = pageSize
      this.requestData(true)
    },
    handleSearch(selectedKeys, confirm, dataIndex, clearFilters) {
      this.current = 1
      this.requestData()
    },
    /* 打开筛选 */
    handleShowFilter() {
      this.showFilter = true
    },
    /* 关闭筛选 */
    closeFilter() {
      this.showFilter = false
    },
    /* 确定筛选 */
    handleFilter() {
      this.handleSearch()
      this.showFilter = false
    },
    /* 删除已选 */
    delFiltered(key) {
      if (key == 'taskStatus' || key == 'deviceCategory') {
        this.filterForm[key] = undefined
      } else if (key == 'reporter') {
        this.filterForm[key] = ''
        this.userIds = ''
        this.userNames = ''
      } else if (key == 'reportTime') {
        this.filterForm.reportDateStart = ''
        this.filterForm.reportDateEnd = ''
        this.filterForm[key] = ''
        this.dateForm[key] = null
      } else if (key == 'createTime') {
        this.filterForm.createDateStart = ''
        this.filterForm.createDateEnd = ''
        this.filterForm[key] = ''
        this.dateFormCreate[key] = null
      } else {
        this.filterForm[key] = ''
      }
    },
    /* 重置筛选 */
    resetFilter() {
      this.filterForm = {
        taskCode: '',
        programName: '',
        deviceCode: '',
        deviceName: '',
        reportTime: null,
        reportDateStart: null,
        reportDateEnd: null,
        createTime: null,
        createDateStart: null,
        createDateEnd: null,
        reporter: '',
        customerId: '',
        flowStatus: undefined,
        deviceCategory: undefined, //设备类型
        taskStatus: '0', //任务状态
      }
      this.dateForm = {}
      this.dateFormCreate = {}
      this.userIds = ''
      this.userNames = ''
      // this.showFilter = false
      this.handleSearch()
    },
    /* 初始/加载设置列 */
    initData() {
      var oldValue = localStorage.getItem(this.BUSI_CONST.Entity.INSPECTION_TASK_LIST)
      this.columns = getNewColumns(this.columnsValue, JSON.parse(oldValue), actionArr, this.columns)
      /* 客户下拉 */
      API.erpCustomerList({ pageSize: 999, pageNo: 1 }).then((res) => {
        if (res.code == 200) {
          this.customSelectList = res.result.records
        }
      })
      ajaxGetDictItems('erp_apply_status').then((res) => {
        if (res.result) {
          this.applyStatusList = res.result
        }
      })
      ajaxGetDictItems('erp_contract_status').then((res) => {
        if (res.result) {
          this.dealStatusList = res.result
        }
      })
      // 字典接口
      getDictModel({ dictCode: 'mess_device_category' }).then((res) => {
        this.dictOptionsDeviceCategory = res.result
      })
      // 字典接口
      getDictModel({ dictCode: 'device_maintain_task_status' }).then((res) => {
        this.dictOptionsTaskStatus = res.result
      })
    },
    /* 请求列表数据 */
    requestData(check) {
      let parameter = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...this.filterForm,
        ...this.sortForm,
      }
      if (parameter.deviceCategory) {
        parameter.deviceCategory = parameter.deviceCategory.join(',')
      }
        // APILX.messDeviceCheckTaskList(parameter).then((res) => {
        //   if (res.code == 200) {
        //     if (res.result.total) {
        //       this.total = res.result.total
        //     } else {
        //       this.total = 0
        //     }
        //     this.modelList = res.result.records
        //       console.log(this.modelList,'---APILX.messDeviceCheckTaskList');
        //   }
        // })
      maintenanceTaskList(parameter).then(res => {
        if (res.code == 200) {
          if (res.result.total) {
            this.total = res.result.total
          } else {
            this.total = 0
          }
          this.modelList = res.result.records
          console.log(res.result.records,'---maintenanceTaskList');
        }
      })
    },
    /* 打开设置列面板 */
    showColumn() {
      this.showSetColumn = true
      this.$nextTick(() => {
        this.$refs.SetColumn.paramsData(this.columnsValue, this.BUSI_CONST.Entity.INSPECTION_TASK_LIST, this.columns)
      })
    },
    /* 设置列 */
    sureBtn(emitArr) {
      this.columns = getNewColumns(this.columnsValue, emitArr, actionArr)
      console.log(this.columns)
      localStorage.setItem(this.BUSI_CONST.Entity.INSPECTION_TASK_LIST, JSON.stringify(emitArr))
      this.tableKey += 1
    },

    /* goDetail() {
      this.$router.push({
        path: '/devicesCare/maintenanceTasksDetail',
      })
    },
    goAdd() {
        this.$router.push({
        path: '/devicesCare/maintenanceTasksAdd',
      })
    },
    goReport() {
        this.$router.push({
        path: '/devicesCare/maintenanceTasksReport',
      })
    }, */
    /* 新建 */
    handleAdd() {
      this.$refs.windowForm.initForm()
      // this.$openWay(this, true, '/devicesCare/maintenanceTasksAdd')
    },
    /* 检查汇报 */
    handleCheckReport(v) {
      this.$refs.maintenanceTasksReport.initForm(v.id)
      // this.$openWay(this, true, '/devicesCare/maintenanceTasksReport', { id: v.id })
      // this.$antdMessage.info('功能开发中')
      // console.log('检查汇报')
    },
    /* 详情 */
    handleDetail(v) {
      this.$refs.windowDetail.initDetail(v.id)
      // this.$openWay(this, true, '/devicesCare/maintenanceTasksDetail', { id: v.id })
    },
    /* 删除 */
    handleDelete(v) {
      let that = this
      that.$antdConfirm({
        title: '请确定要删除此设备吗?',
        content: ``,
        onOk() {
          that.clearArr()
          API.messDeviceDelete(v.id).then((res) => {
            if (res.code == 200) {
              that.$antdMessage.success('设备删除成功！')
              that.handleSearch()
            } else {
              that.$antdMessage.error(res.message)
            }
          })
        },
        onCancel() {},
      })
    },
    //点击返回按钮
    goBack() {
      console.log('goback')
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/public.less';
.flex(@jc,@ai,@fd:row) {
  display: flex;
  justify-content: @jc;
  align-items: @ai;
  flex-direction: @fd;
}
.header {
  width: 150%;
  margin: -12px -12px @distance4;
}
.backBox {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .backC {
    cursor: pointer;
    display: flex;
    align-items: center;
  }
}
.j-table-force-nowrap {
  margin-top: @distance1;
}
.btns {
  margin-left: @distance5;
}
.right-btn {
  float: right;
  display: flex;
  justify-content: flex-end;
}
.mg-left {
  margin-left: @distance3;
}
.filter-tit {
  background: #fff;
  border-bottom: 1px solid @greyBorder;
  font-size: @fontSize4;
}
.filter-num {
  color: @normalFont;
}
.filter-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.margin-btn {
  margin-right: @distance5;
}
.filter-tag {
  display: inline-block;
  position: relative;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: @fontSize1;
  line-height: @fontSize1;
  max-width: 100%;
  background: @greyBg;
  color: @titFont;
  cursor: pointer;
  .tag-text {
    display: inline-block;
    padding-right: 20px;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .anticon-close {
    position: absolute;
    right: 8px;
    top: 8px;
  }
}
.tag-wrap:nth-of-type(n + 2) {
  margin-top: 10px;
}
.searchWorkOreder {
  .flex(flex-start, center);
  padding: 8px;
}
.pagebox {
  /deep/ .ant-card-body {
    height: calc(100vh - 214px);
    overflow: hidden;
    padding: 20px 16px;
  }
}
/deep/ .ant-calendar-range{
  width: 100%;
}
</style>
